\chapter{Graphics}

As of durexForth v1.2, high-resolution graphics support is included.

\section{Turtle Graphics}

Turtle graphics are mostly known from LOGO, a 1970s programming language.
It enables control of a turtle that can move and turn while holding a pen.
The turtle graphics library is loaded with \texttt{s" turtle" load}.

\begin{description}
\item[init ( -- )] Initializes turtle graphics.
\item[forward ( px -- )] Moves the turtle \texttt{px} pixels forward.
\item[back ( px -- )] Moves the turtle \texttt{px} pixels back.
\item[left ( deg -- )] Rotates the turtle \texttt{deg} degrees left.
\item[right ( deg -- )] Rotates the turtle \texttt{deg} degrees right.
\item[penup ( -- )] Pen up (disables drawing).
\item[pendown ( -- )] Pen down (enables drawing).
\end{description}

\section{High-Resolution Graphics}

The high-resolution graphics library is loaded with \texttt{s" gfx" load}. 
It is inspired by "Step-by-Step Programming Commodore 64: Graphics Book 3."
Some demonstrations can be found in \texttt{gfxdemo}. 
\begin{description}
\item[hires ( -- )] Enters the high-resolution drawing mode.
\item[lores ( -- )] Switches back to low-resolution text mode.
\item[clrcol ( colors -- )] Clears the high-resolution display using \texttt{colors}. Colors is a
byte value with foreground color in high nibble, background color in low nibble. E.g. \texttt{15
clrcol} clears the screen with green background, white foreground.
\item[blkcol ( col row colors -- )] Changes colors of the 8x8 block at given position.
\item[plot ( x y -- )] Sets the pixel at x, y.
\item[peek ( x y -- p )] Gets the pixel at x, y.
\item[line ( x y -- )] Draws a line to x, y.
\item[circle ( x y r -- )] Draws a circle with radius r around x, y.
\item[erase ( mode -- )] Changes blit method for line drawing. \texttt{1 erase} uses \texttt{xor}
for line drawing, \texttt{0 erase} switches back to \texttt{or}.
\item[paint ( x y -- )] Paints the area at x, y.
\item[text ( column row str strlen -- )] Draws a text string at the given position. E.g. \texttt{10
8 s" hallo" text} draws the message "hallo" at column 16, row 8.
\item[drawchar ( column row char -- )] Draws a custom character at given column and row.
\item[defchar] Defines an 8x8 character to use with the \texttt{drawchar} word. Example:

\begin{verbatim}
defchar sqr
00000000
00000000
00111100
00111100
00111100
00111100
00000000
00000000
2 2 sqr drawchar
\end{verbatim}

...draws a square at column 2, row 2.
\end{description}
